﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class aspx_communication_msg : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        databind();
    }
    private void databind()
    {
        PagedDataSource ps = new PagedDataSource();
        using (ds_名师讲堂TableAdapters.tb_交流互动TableAdapter da = new ds_名师讲堂TableAdapters.tb_交流互动TableAdapter())
        {
            ps.DataSource = da.GetDataBy显示(true).DefaultView;
        }
        ps.AllowPaging = true;
        ps.PageSize = 6;
        ps.CurrentPageIndex = getIndex() ;
       setCount( ps.DataSourceCount);
        this.rpt交流互动.DataSource = ps;
        this.rpt交流互动.DataBind();
    }

    protected void btn首页_Click(object sender, EventArgs e)
    {
        setIndex(0);
        databind();
    }
    protected void btn尾页_Click(object sender, EventArgs e)
    {
        setIndex( getCount()/6);
        databind();
    }
    protected void btn前一页_Click(object sender, EventArgs e)
    {
        if (getIndex()>0)
        {
            setIndex(getIndex()-1);
            databind();
        }
    }
    protected void btn后一页_Click(object sender, EventArgs e)
    {
        if (getIndex() <getCount()/6)
        {
            setIndex(getIndex() + 1);
            databind();
        }
    }


    protected void btn提交_Click(object sender, EventArgs e)
    {
        if (txt验证码.Text.ToString() == Session["check"].ToString())
        {
            lbl提示消息.Text = "提交成功！";
            using (ds_名师讲堂TableAdapters.tb_交流互动TableAdapter da = new ds_名师讲堂TableAdapters.tb_交流互动TableAdapter())
            {
                da.Insert(txt姓名.Text, txt联系邮箱.Text, txt联系电话.Text, txt留言内容.Text, null, false, DateTime.Now, null);
            }
            WebHelper.MessageBox.Show("留言成功！感谢您的留言，待通过审核之后您的宝贵留言将会显示在留言板上，谢谢。");
        }
        else
        { 
            lbl提示消息.Text = "验证码错误！";
        }
      
    }

    private int getIndex()
    {
        return Convert.ToInt32(lbl页码.Text);
    }

    private int getCount()
    {
        return Convert.ToInt32(lbl总页数.Text);
    }
    private void setIndex(int index)
    {
        this.lbl页码.Text = index.ToString();
    }

    private void setCount(int count)
    {
        this.lbl总页数.Text = count.ToString();
    }
    protected void rpt交流互动_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Label lbl回复 = e.Item.FindControl("lbl回复") as Label;
        if (lbl回复.ToolTip.Length==0)
        {
            lbl回复.Visible = false;
        }
    }
}